package com.rom.queue;

public class ArrayQueueDemo {
    public static void main(String[] args) {
        ArrayQueue arr = new ArrayQueue(3);
        arr.addQueue(1);
        arr.addQueue(2);
        arr.addQueue(3);
        arr.showQueue();
    }

}
//数组队列
class ArrayQueue{

    private int maxSize;
    private int front;
    private int rear;

    private int[] arr;

    public ArrayQueue(int arrMaxSize){
        maxSize = arrMaxSize;
        arr = new int[maxSize];
        front = -1;
        rear = -1;
    }
    public boolean isFull(){
        return rear == maxSize - 1;
    }
    public boolean isEmpty(){
        return rear == front;
    }
    //添加值到队列
    public void addQueue(int n){
        if(isFull()){
            System.out.println("队列满，不能加入数据-");
            return;
        }
        arr[++rear] = n;
    }
    //取出数据
    public int getQueue(){
        if(isEmpty()){
            throw new RuntimeException("队列空,不能取出数据");
        }
        return arr[++front];
    }
    //数组遍历
    public void showQueue(){
        if(isEmpty()){
            System.out.println("队列空的、没有数据");
            return;
        }
        for (int i = 0; i < arr.length; i++) {
            System.out.printf("arr[%d]=%d\t",i,arr[i]);
        }
    }
    //显示数组的头数据是多少
    public int headQueue(){
        if(isEmpty()){
            throw new RuntimeException("队列空的、没有数据...");
        }
        return arr[++front];
    }
}
